# 智力测试
# 意义不明

from collections import Counter
from bisect import bisect_left, bisect_right

n, m, T = map(int, input().split())
R = list(map(int, input().split()))
C = list(map(int, input().split()))

cntR = Counter(R)
cntC = Counter(C)

r = sorted(list(cntR.keys()))
c = sorted(list(cntC.keys()))
mod = 10 ** 9 + 7

preR = [1]
preC = [1]
for x in r:
    preR.append((preR[-1] * cntR[x]) % mod)
for x in c:
    preC.append((preC[-1] * cntC[x]) % mod)


def prod(a, l, r):
    if l > r:
        return 1
    return a[r + 1] * inv(a[l])


fac = [1]
for i in range(1, n + m):
    fac.append((fac[-1] * i) % mod)


def inv(x):
    return pow(x, mod - 2, mod)


for _ in range(T):
    r1, c1, r2, c2 = map(lambda x: int(x) - 1, input().split())
    # print(r1,c1,r2,c2,'...',R[r1], C[c1], R[r2], C[c2])
    if R[r1] > R[r2] or C[c1] > C[c2]:
        print(0)
        continue
    if R[r1] == R[r2] and r1 != r2:
        print(0)
        continue
    if C[c1] == C[c2] and c1 != c2:
        print(0)
        continue
    x1, x2 = bisect_left(r, R[r1]), bisect_left(r, R[r2])
    y1, y2 = bisect_left(c, C[c1]), bisect_left(c, C[c2])
    # print(x1,x2,y1,y2)
    res = prod(preR, x1 + 1, x2 - 1) * prod(preC, y1 + 1, y2 - 1)
    a, b = x2 - x1 + y2 - y1, x2 - x1
    res *= fac[a] * inv(fac[b]) * inv(fac[a - b])  # f.comb(x2-x1+y2-y1,x2-x1)
    res %= mod
    print(res)
